<template>
  <a-spin :loading="loading" style="width: 100%">
    <a-card :bordered="false" :style="cardStyle">
      <div class="content-wrap">
        <div class="content">
          <a-statistic :title="props.title" :value="config?.count" :value-from="0" animation show-group-separator />
          <div class="desc flex items-center">
            <a-typography-text type="secondary" class="label"> {{ config?.text }} </a-typography-text>
            <a-typography-text v-if="config?.type === 'rise'" type="danger">
              {{ config?.growth }}
              <icon-arrow-rise />
            </a-typography-text>
            <a-typography-text v-else type="success">
              {{ config?.growth }}
              <icon-arrow-fall />
            </a-typography-text>
          </div>
        </div>
        <div class="chart">
          <sa-chart v-if="!loading" :option="config?.chartOption" />
        </div>
      </div>
    </a-card>
  </a-spin>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  chartData: {
    type: Object,
    default: () => {
      return {
        count: 0,
        text: '较昨日',
        growth: '0',
        type: 'rise',
        chartOption: {},
      }
    },
  },
  cardStyle: {
    type: Object,
    default: () => {
      return {}
    },
  },
})

const loading = ref(false)
const config = ref({})

watch(
  () => props.chartData,
  (vl) => {
    if (vl) {
      config.value = vl
    }
  },
  { immediate: true }
)
</script>

<style scoped lang="less">
:deep(.arco-card) {
  border-radius: 4px;
}
:deep(.arco-card-body) {
  width: 100%;
  height: 134px;
  padding: 0;
}
.content-wrap {
  width: 100%;
  padding: 16px;
  white-space: nowrap;
}
:deep(.content) {
  float: left;
  width: 108px;
  height: 102px;
}
:deep(.arco-statistic) {
  .arco-statistic-title {
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
  }
  .arco-statistic-content {
    margin-top: 10px;
  }
}

.chart {
  float: right;
  width: calc(100% - 108px);
  height: 90px;
  vertical-align: bottom;
}

.label {
  padding-right: 8px;
  font-size: 12px;
}
</style>
